package com.service;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Service
public class RedisService {

    @Autowired
    private RedisTemplate redisTemplate;

    /**
     *
     * @param set1  好友列表1
     * @param set2  好友列表2
     * @return      共同好友
     */
    public Set commonFriends(Set set1, Set set2) {
        redisTemplate.delete("set1");
        redisTemplate.delete("set2");
        List list1 = new ArrayList(set1);
        List list2 = new ArrayList(set2);
        redisTemplate.boundSetOps("set1").add(list1.toArray());
        redisTemplate.boundSetOps("set2").add(list2.toArray());
        Set result = redisTemplate.opsForSet().intersect("set1","set2");
        return result;
    }

}
